package com.sgb.knowledgeshare.viewmodel;

import android.util.Log;

import androidx.lifecycle.ViewModel;

import com.sgb.knowledgeshare.ShareConfig;
import com.sgb.knowledgeshare.entity.ShareDictEntity3;
import com.sgb.knowledgeshare.view.activity.PlayListActivity;
import com.sgb.knowledgeshare.weight.ControllerView;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.VideoBean;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;
import com.swgk.core.view.entity.VideoListEntity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class PlayListModelModel extends ViewModel {
    PlayListActivity activity;
    private ArrayList<Long> delectList;
    private int page;
    public void setActivity(PlayListActivity playListActivity) {
        activity = playListActivity;
    }

    /*
     * 视频播放次数实现
     * */
    public void getplayVideo(String videoId) {
        Map map = new HashMap();
        map.put("videoId", videoId);
       ShareConfig.getInstance().getApi().getplayVideos(map).enqueue(new ICallBack<BaseEntity>() {
           @Override
           public void onSuccess(BaseEntity data) {

           }
       });
    }

    //    获取对应的类型列表数据
    public void getVideoTypeList(int page, String no) {
        Map map = new HashMap();
        map.put("pageNum", page);
        map.put("pageSize", 10);
        map.put("type", no);//类型id
        Log.e("tag", "pageNum:" + page + "  type:" + no);
       ShareConfig.getInstance().getApi().getVideoListByType(map).enqueue(new ICallBack<BaseEntity<VideoListEntity>>() {
           @Override
           public void onSuccess(BaseEntity<VideoListEntity> data) {
               DialogHelper.dismissProgressDialog();
               if (data.getData() == null) return;
               if (data.getState().equals("ok")) {
                   activity.setVideoTypeList(data.getData().getRecords());
               }
           }
       });
    }

    /*
     *用户中心数据
     */
    public void getVideoListData(int page, String userid, String userShareType) {
        Map map = new HashMap();
        map.put("pageNum", page);
        map.put("pageSize", "10");
        map.put("userNo", userid);
        map.put("type", userShareType);
        map.put("videoId", "");
       ShareConfig.getInstance().getApi().getmyVodList(map).enqueue(new ICallBack<BaseEntity<VideoListEntity>>() {
           @Override
           public void onSuccess(BaseEntity<VideoListEntity> data) {
               DialogHelper.dismissProgressDialog();
               if (data.getData() == null) {
                   return;
               }
               if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                   activity.setVideoTypeList(data.getData().getRecords());
               }
           }
       });
    }

    //获取评论数量
    public void getCommentNum(VideoBean videoData, ControllerView controllerView) {
        Map map = new HashMap();
        map.put("videoId", videoData.getVideoId());//longitude
       ShareConfig.getInstance().getApi().getCommentCount(map).enqueue(new ICallBack<BaseEntity<ShareDictEntity3>>() {
           @Override
           public void onSuccess(BaseEntity<ShareDictEntity3> data) {
               if (data.getData() == null) {
                   return;
               }
               if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                   videoData.setCommentCount(Integer.parseInt(data.getData().getParam()));
                   activity.setCommentNum(videoData, controllerView);
               }
           }
       });
    }

    //点赞的操作
    public void setLike(String s) {
        Map map = new HashMap();
        map.put("videoId", s);//longitude
       ShareConfig.getInstance().getApi().getlike(map).enqueue(new ICallBack<BaseEntity>() {
           @Override
           public void onSuccess(BaseEntity data) {

           }
       });
    }

    /*
     * 点击+号关注的实现
     * */
    public void getFens(String userid) {
        Map map = new HashMap();
        map.put("userNo", userid);
       ShareConfig.getInstance().getApi().getfens(map).enqueue(new ICallBack<BaseEntity>() {
           @Override
           public void onSuccess(BaseEntity data) {

           }
       });
    }

    public void deleteMyVideo(int id) {
        delectList = new ArrayList<>();
        delectList.add((long) id);
        DialogHelper.showProgressDialog(activity, null, "删除中...", 0, true, null).setCanceledOnTouchOutside(false);
       ShareConfig.getInstance().getApi().getDeleteMyVideo(delectList).enqueue(new ICallBack<BaseEntity>() {
           @Override
           public void onSuccess(BaseEntity data) {
               DialogHelper.dismissProgressDialog();
               if (data.getData() == null) {
                   return;
               }
               if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                   MToast.showToast(activity, "删除视频成功！");
                   activity.setDeleteList(id);
               }
           }
       });
    }

    //标签视频列表详情信息
    public void getVideLabelPage(int page, String labelNo) {
        Map map = new HashMap();
        map.put("page", page);
        map.put("limit", 10);
        map.put("labelNo", labelNo);
       ShareConfig.getInstance().getApi().getVideLabelPage(map).enqueue(new ICallBack<BaseEntity<VideoListEntity>>() {
           @Override
           public void onSuccess(BaseEntity<VideoListEntity> data) {
               if (data.getData() == null) return;
               if (data.getState().equals("ok")) {
                   activity.setVideoTypeList(data.getData().getRecords());
               }
           }
       });
    }

    //首页跳转的数据信息
    public void getHomeVideoListData(int page, String videoType) {
        Map map = new HashMap();
        map.put("page", page);
        map.put("limit", 10);
        map.put("videoIds", new ArrayList<>());
        map.put("type", videoType);
        DialogHelper.showProgressDialog(activity, null, "加载中...", 0, true, null).setCanceledOnTouchOutside(false);
       ShareConfig.getInstance().getApi().getIndexVodList(map).enqueue(new ICallBack<BaseEntity<VideoListEntity>>() {
           @Override
           public void onSuccess(BaseEntity<VideoListEntity> data) {
               DialogHelper.dismissProgressDialog();
               if (data.getData() == null) return;
               if (data.getState().equals("ok")) {
                   activity.setHomeVideoListData(data.getData());
               }
           }
       });
    }

    //集采数据类型
    public void getVideoList(int page) {
        Map map = new HashMap<>();
        map.put("limit", 10);
        map.put("page", page);
        map.put("parentName","网站经营");
        map.put("name","集采/团购");
        DialogHelper.showProgressDialog(activity, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        ShareConfig.getInstance().getApi().getVodListByCondition(map).enqueue(new ICallBack<BaseEntity<VideoListEntity>>() {
            @Override
            public void onSuccess(BaseEntity<VideoListEntity> data) {
                DialogHelper.dismissProgressDialog();
                activity.setVideoTypeList(data.getData().getRecords());
            }
        });
    }

    /**
     * 租赁视频列表
     * name 二级名称
     * parentName  一级名称
     */
    public void getVideo(int page) {
        Map map = new HashMap();
        map.put("page", page);
        map.put("limit", 10);
        map.put("name", "经营租赁");
        map.put("parentName", "网站经营");
        ShareConfig.getInstance().getApi().getHomeVideoList(map).enqueue(new ICallBack<BaseEntity<VideoListEntity>>() {
            @Override
            public void onSuccess(BaseEntity<VideoListEntity> data) {
                if (data.getData() != null && data.getData().getRecords() != null) {
                    activity.setVideoTypeList(data.getData().getRecords());
                }
            }
        });
    }

    //知识分享接口
    public void memberVideoShare(int page){
        Map map = new HashMap();
        map.put("page",page);
        map.put("limit",8);
        map.put("secondCategory","招标/竞价");
        ShareConfig.getInstance().getApi().memberVideoShare(map).enqueue(new ICallBack<BaseEntity<VideoListEntity>>() {
            @Override
            public void onSuccess(BaseEntity<VideoListEntity> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(ShareConfig.RESPONSE_OK)) {
                    activity.setVideoTypeList(data.getData().getRecords());
                }
            }
        });
    }


}
